home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / ghostscript / src / gxcache.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  106 lines

  1. /* Copyright (C) 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gxcache.h */
  20. /* Definitions for character cache */
  21. /* Requires gxchar.h or gxcdir.h */
  22. #include "gsuid.h"
  23. #include "gsxfont.h"
  24.  
  25. /* An entry for a (font,matrix) pair in the character cache. */
  26. /* If UID is valid, font may be 0, since we keep entries for fonts */
  27. /* unloaded by a restore if they have valid UIDs. */
  28. struct cached_fm_pair_s {
  29.     struct gs_font_s *font;        /* base font */
  30.     gs_uid UID;            /* font UniqueID or XUID */
  31.     float mxx, mxy, myx, myy;    /* transformation */
  32.     int num_chars;            /* # of cached chars with this */
  33.                     /* f/m pair */
  34.     int xfont_tried;        /* true if we looked up an xfont */
  35.     gx_xfont *xfont;        /* the xfont (if any) */
  36.     const gs_memory_procs *mprocs;    /* the allocator for the xfont */
  37. };
  38. /* If font == 0 and UID is invalid, this is a free entry. */
  39. #define fm_pair_is_free(pair)\
  40.   ((pair)->font == 0 && !uid_is_valid(&(pair)->UID))
  41. #define fm_pair_set_free(pair)\
  42.   ((pair)->font = 0, uid_set_invalid(&(pair)->UID))
  43.  
  44. /* The character cache contains both used and free blocks. */
  45. /* All blocks have a common header; free blocks have ONLY the header. */
  46. typedef struct cached_char_head_s {
  47.     uint size;            /* total block size in bytes */
  48.     cached_fm_pair *pair;        /* font/matrix pair, 0 if free */
  49. } cached_char_head;
  50. #define cc_head_is_free(cch) ((cch)->pair == 0)
  51. #define cc_head_set_free(cch) ((cch)->pair = 0)
  52. /*
  53.  * A cached bitmap for an individual character.
  54.  * The bits, if any, immediately follow the structure;
  55.  * characters with only xfont definitions may not have bits.
  56.  * We maintain the invariant that if cc->head.pair != 0 (the character
  57.  * is visible in the cache), at least one of the following must be true:
  58.  *    - cc_has_bits(cc);
  59.  *    - cc->xglyph != gx_no_xglyph && cc->head.pair->xfont != 0.
  60.  */
  61. struct char_cache_chunk_s;
  62. #ifndef cached_char_DEFINED
  63. #  define cached_char_DEFINED
  64. typedef struct cached_char_s cached_char;
  65. #endif
  66. struct cached_char_s {
  67.     /* The code, font/matrix pair, and wmode */
  68.     /* are the 'key' in the cache. */
  69.     cached_char_head head;        /* (must be first, */
  70.                     /* references font/matrix pair) */
  71.     gs_glyph code;            /* glyph code */
  72.     ushort wmode;            /* writing mode (0 or 1) */
  73.     cached_char *next;        /* next in replacement ring */
  74.     struct char_cache_chunk_s *chunk;    /* chunk where this char */
  75.                     /* is allocated */
  76.     /* The rest of the structure is the 'value'. */
  77.     gx_xglyph xglyph;        /* the xglyph for the xfont, if any */
  78.     ushort raster, height;        /* dimensions of bitmap */
  79.     ushort width;
  80.     gx_bitmap_id id;        /* if null, no bits follow */
  81.     gs_fixed_point wxy;        /* width in device coords */
  82.     gs_fixed_point offset;        /* (-llx, -lly) in device coords */
  83. };
  84. #define cc_is_free(cc) cc_head_is_free(&(cc)->head)
  85. #define cc_set_free(cc) cc_head_set_free(&(cc)->head)
  86. #define cc_has_bits(cc) ((cc)->id != gx_no_bitmap_id)
  87.  
  88. /* Define the size of the cache structures. */
  89. /* We round the size of a cached_char so that */
  90. /* an immediately following bitmap will be properly aligned. */
  91. #define align_cached_char_mod\
  92.   (max(align_bitmap_mod, max(arch_align_ptr_mod, arch_align_long_mod)))
  93. #define sizeof_cached_char\
  94.   round_up(sizeof(cached_char), align_cached_char_mod)
  95. #define cc_bits(cc) ((byte *)(cc) + sizeof_cached_char)
  96.  
  97. /* Define the hash chain for a (glyph, fm_pair) key. */
  98. /* The OSF/1 compiler doesn't like casting a pointer to a shorter int. */
  99. #if arch_sizeof_ptr == arch_sizeof_int
  100. typedef uint ptr_uint_t;
  101. #else
  102. typedef ulong ptr_uint_t;
  103. #endif
  104. #define chars_head(dir, glyph, pair)\
  105.   &(dir)->ccache.chars[((uint)(glyph) + ((ptr_uint_t)(pair) << 4)) & (dir)->ccache.chars_mask]
  106.